package com.yangguang.huahui.ui.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;

import com.yangguang.huahui.Config;
import com.yangguang.huahui.R;
import com.yangguang.huahui.baseadapter.BaseQuickAdapter;
import com.yangguang.huahui.entity.AttentionList;
import com.yangguang.huahui.mvp.presenter.AttentionPresenter;
import com.yangguang.huahui.mvp.view.AttentionView;
import com.yangguang.huahui.ui.activitys.DetailActivity;
import com.yangguang.huahui.ui.adapters.MiaomuAdapter;
import com.yangguang.huahui.utils.LogUtil;
import com.yangguang.huahui.widget.FullyLinearLayoutManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2017/3/2.
 */

public class AttentionFragment extends BaseMvpFragment<AttentionView, AttentionPresenter> implements AttentionView, View.OnTouchListener {
    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;
    private FullyLinearLayoutManager layoutManager;
    private MiaomuAdapter mAdapter;
    private List<AttentionList.ListBean> datas = new ArrayList<>();
    @Override
    public void onSuccess(AttentionList data) {
        if (data.getList() != null){
            datas = data.getList();
        }
       mAdapter.setNewData(datas);
    }

    @Override
    public void onError() {

    }

    @Override
    protected AttentionPresenter initPresenter() {
        return new AttentionPresenter();
    }

    @Override
    protected void fetchData() {
        mPresenter.getListData(getArguments().getString("id"));
    }

    @Override
    protected int initLayoutId() {
        return R.layout.frag_attention;
    }

    @Override
    protected void initView() {
        layoutManager = new FullyLinearLayoutManager(mActivity);
        layoutManager.setSmoothScrollbarEnabled(true);
        layoutManager.setAutoMeasureEnabled(true);

        mRecyclerView.setLayoutManager(layoutManager);
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setNestedScrollingEnabled(false);
        mAdapter = new MiaomuAdapter(R.layout.find_miaomu_list_item, null);
        mAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setOnRecyclerViewItemClickListener(new BaseQuickAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                startActivity(new Intent(mActivity, DetailActivity.class)
                        .putExtra("webUrl", Config.SUPPLY_DETAIL)
                        .putExtra("id", mAdapter.getItem(position).getId()));
            }
        });
        mRecyclerView.setOnTouchListener(this);
    }

    @Override
    protected void initData() {
        if (getArguments() == null) {
            return;
        }
    }

    public static AttentionFragment newInstance(String id) {
        AttentionFragment fragment = new AttentionFragment();
        Bundle arguments = new Bundle();
        arguments.putString("id", id);
        fragment.setArguments(arguments);
        return fragment;
    }

    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        return false;
    }
}
